module.exports = class extends baseController{
    constructor(){
        super();
        this.siteModuleLogic=this.loadLogic('cms/site-module');
        this.router.post('/getItems',this.getItems.bind(this));
        this.router.post('/getItem',this.getItem.bind(this));
        this.router.post('/edit',this.edit.bind(this));
        this.router.post('/del',this.del.bind(this));
        return this.router;
    }

    async getItems(req,res){
        let Result={};
        try {
            let Ret = await this.siteModuleLogic.getItems();
            Result=this.Success(1,Ret);
        } catch (err) {
            Result=this.Error("查询失败",err);
        }
        res.json(Result);
    }

    async getItem(req,res){
        let Result={};
        let id=req.body.id || '';
        try {
            let Ret = await this.siteModuleLogic.getItem(id);
            Result=this.Success(1,Ret);
        } catch (err) {
            Result=this.Error("查询失败",err);
        }
        res.json(Result);
    }

    async edit(req,res){
        let Result={};
        let model={
            sm_id:req.body.sm_id || '',
            sm_name:req.body.sm_name,
            sm_viewPath:req.body.sm_viewPath,
            sm_remark: req.body.sm_remark,
            sm_url:req.body.sm_url,
            sm_keyWord:req.body.sm_keyWord,
            sm_pageTitle:req.body.sm_pageTitle
        };
        try {
            let Ret = await this.siteModuleLogic.edit(model);
            Result=this.Success(1,Ret);
        } catch (err) {
            Result=this.Error("查询失败",err);
        }
        res.json(Result);
    }

    async del(req,res){
        let Result={};
        let id=req.body.id || '';
        try {
            let Ret = await this.siteModuleLogic.del(id);
            Result=this.Success(1,Ret);
        } catch (err) {
            Result=this.Error("删除失败",err);
        }
        res.json(Result);
    }
};